﻿@{
    ViewData["Title"] = "修改外协发料";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <!-- 给容器追加 class="layui-form-pane"，即可显示为方框风格 -->
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">发料单编号</label>
            <div class="layui-input-block">
                <input type="text" name="IssueCode" id="IssueCode" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">发料单名称</label>
            <div class="layui-input-block">
                <input type="text" name="IssueName" id="IssueName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">外协工单编码</label>
            <div class="layui-input-block">
                <input type="text" name="WorkorderCode" id="WorkorderCode" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">供应商名称</label>
            <div class="layui-input-block">
                <input type="text" name="VendorName" id="VendorName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">发料日期</label>
            <div class="layui-input-inline layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-date"></i>
                </div>
                <input type="text" name="IssueDate" id="IssueDate" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">单据状态</label>
            <div class="layui-input-block">
                <input type="text" name="Status" id="Status" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="demo2">修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>

    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        layui.use(['form'], function () {
            var layer = layui.layer;
            var form = layui.form;
            var laydate = layui.laydate;

            // 日期
            laydate.render({
                elem: '#IssueDate'
            });

            //反填
            function generateVendorCode() {
                $("#IssueCode").val(parent.IssueCode);
                $("#IssueName").val(parent.IssueName);
                $("#WorkorderCode").val(parent.WorkorderCode);
                $("#VendorName").val(parent.VendorName);
                $("#IssueDate").val(parent.IssueDate);
                $("#Status").val(parent.Status);
            }
            generateVendorCode()


            // 表单提交事件
            form.on('submit(demo2)', function (data) {
                var field = data.field; // 获取表单字段值
                console.log(field);
                var UpdateDto = {
                    //获取表单
                    IssueCode: field.IssueCode,
                    IssueName: field.IssueName,
                    WorkorderCode: field.WorkorderCode,
                    VendorName: field.VendorName,
                    IssueDate: field.IssueDate,
                    Status: field.Status,

                    //数据库值
                    Id : parent.Id ,
                    WorkorderId : parent.WorkorderId ,
                    VendorId : parent.VendorId ,
                    VendorCode : parent.VendorCode ,
                    VendorNick : parent.VendorNick ,
                    LocationId : parent.LocationId ,
                    LocationCode : parent.LocationCode ,
                    LocationName : parent.LocationName ,
                    AreaId : parent.AreaId ,
                    AreaCode : parent.AreaCode ,
                    AreaName : parent.AreaName ,
                    WarehouseId : parent.WarehouseId ,
                    WarehouseCode : parent.WarehouseCode ,
                    WarehouseName : parent.WarehouseName ,
                    Remark : parent.Remark ,
                    CreateBy : parent.CreateBy ,
                    CreateTime : parent.CreateTime ,
                }
                $.ajax({
                    url: "/Meng/UpdateOutSource",
                    type: "get",
                    async: true,
                    data: UpdateDto,
                    contentType: "application/json",
                    success: res => {
                        if (res == 1) {
                            alert("修改成功")
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                        else {
                            console.log(res.code)
                            alert("修改失败")
                        }
                    }
                });
                console.log("1")
                return false; // 阻止默认 form 跳转
            });
        });

    </script>

</body>
</html>